console.log('深拷贝')

let obj1 = {
    city: 'shanghai',
    num: 1,
    arr: ['1', 2, 3],
    s: {
        a: {b:2}
    }
}
const obj2 = deepClone(obj1)
obj2.city = 'beijing'
console.log(obj1.city)
/**
 * 深拷贝
 * @param {} obj 
 */
function deepClone (obj) {
    if (typeof obj !== 'object' || obj == null) {
        return obj
    }
    let res
    if (obj instanceof Array) {
         res = []
    }
    else {
        res = {}
    }
    for (let key in obj) {
        if (obj.hasOwnProperty(key)) {
            res[key] = deepClone(obj[key])
        }

    }
    return res

}

/**
 * 浅kaobei
 */

// let obj3 = Object.assign({}, obj1)

// obj3.city='taiyuan'
// obj3.s.a.b=3
// console.log(obj3)
// console.log(obj1)

let obj4 = {...obj1};
obj4.s.a.b=4444
console.log('obj4',obj4)
console.log(obj1)
// console.log(obj2)
